package com.spatio.serving.basic.service.template.core.biz;

import com.spatio.serving.basic.service.template.common.dto.dify.DifyCommon;
import com.spatio.serving.basic.service.template.common.req.AskSimpleReq;
import com.spatio.serving.basic.service.template.common.vo.UrlUploadInfo;
import com.spatio.serving.basic.service.template.core.component.invoker.DifyInvoker;
import com.spatio.serving.basic.service.template.core.component.invoker.OssInvoker;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigInteger;
import java.util.List;
import java.util.Map;

/**
 * @Description
 * @Author GuoPengfei
 * @Date 2024/7/3 09:53
 */
@Component
@Slf4j
public class DiaLogBiz {

    @Autowired
    private DifyInvoker difyInvoker;
    @Autowired
    private OssInvoker ossInvoker;

    public DifyCommon askSimpleStream(BigInteger userId,AskSimpleReq askReq, HttpServletResponse res) throws IOException {
        DifyCommon difyCommon = difyInvoker.chatMessagesStream(userId,askReq.getQuestionText(), askReq.getUrl(),
                                                        askReq.getDifyConversationId(),askReq.getMessageId(), res);
        return difyCommon;
        // Business code
    }

    public void askSimpleStreamV2(BigInteger userId,AskSimpleReq askReq, HttpServletResponse res) throws IOException {
        difyInvoker.chatMessagesStreamV2(userId,askReq.getQuestionText(), askReq.getUrl(),
                askReq.getDifyConversationId(),askReq.getMessageId(), res);

    }

    //完成记录推荐对话流
    public void recommendFoodStream(BigInteger user_id, AskSimpleReq askReq , HttpServletResponse res , Map map) throws IOException {
        difyInvoker.afterRecordRecommend(user_id,askReq,res,map);

    }

    public UrlUploadInfo uploadFile(MultipartFile file , String region , String bizType, String contentType) throws IOException {
        UrlUploadInfo info = ossInvoker.upload(file, region , bizType , contentType);
        return info;
    }

    public Map<String,String> getUrl(List<String> uris) throws IOException {
        Map<String,String> ans = ossInvoker.getOssCompleteUrl3Times(uris);
        return ans;
    }

    public String getOpen() {
        String res=difyInvoker.getOpenStatement();
        return res;
    }
}